put
Type
command
Summary
Places a value into a container.
Syntax
put <value> [{before | into | after} <container>]
put <value> into URL <destinationURL>
Description
Use the put command to set the value of a variable, put text into a field, put data into a file, display text in the message box, or upload a file to a server.
If you use the put into form, the value replaces anything that was previously in the container. The put before and put after forms place the value before or after the current contents of the container. If you do not specify a container, the put command puts the value into the message box.
If you put a value into a nonexistent container, LiveCode assumes it is a variable name, and initializes the container as a local variable. This is the most common way to create a local variable. You can also explicitly declare local variables with the local command. If the explicitVariables property is set to true, you must declare local variables before using them, and using the put command with a nonexistent variable causes an error instead of creating the variable.
The action of the put...into URL form varies depending on the type of URL:
- When used with a file or binfile URL, places the value in the specified file. If the file does not exist, the put command creates it. Use the file URL type for text data and the binfile URL type for binary data.
local tResult
put tData into url (file: tFilePath)
if tResult is not empty then
# Handle error here
else
# Continue execution
end if
- When used with a resfile URL, sets the resource fork of the specified file to the value. Because resource fork|resource forks have a specific format, in general you should use put with a resfile URL only when the value is also a resfile URL. The following example copies the entire resource fork of one file to another:
put URL resfile:My Source into URL resfile:Destination
put empty into URL file:filePath
Then you can use the put command with a resfile URL type to create the resource fork.
The syntax for file URLs with LiveCode's URL
does not conform to RFC 1738.
To ensure proper operation on all platforms make sure you use
file:path
rather than file://path
.
- When used with an http URL, uses the HTTP PUT method to upload the value to the server. However, since most HTTP servers don't implement the PUT method, you usually will use an FTP URL instead to upload files to an HTTP server.
Uploading a URL by putting a value into it is a blocking operation: that is, the handler pauses until LiveCode is finished Uploading the value. Since contacting a server may take some time due to network lag, URL operations may take long enough to be noticeable to the user. To upload without blocking, use the libURLftpUpload command instead.
On windows, it is imperative not to name a file with one of the reserved device names: CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8 and LPT9. Also do not use these names followed by an extension, for example, NUL.tx7.
The Android and iOS engines do not support 'libUrl' but do allow you to use put in the background. When specifying URLs for iOS, you must use the appropriate form that conforms to RFC 1738. Ensure that you URLEncode any username and password fields appropriately for FTP URLs.
The Web engine only supports HTTP and HTTPs protocols.
URLs fetched by the Web engine from a domain other than that of the hosting the page may be blocked by web browsers, unless the server hosting the URL sets the "Access-Control-Origin" header appropriately.
Parameters
Name | Type | Description |
---|---|---|
value | string | |
container | The container into which the value should be placed. This usually an object reference or a variable name. | |
destinationURL |
Examples
put "ABC"
put 3 + 12 into myVariable
put return & someGlobalVar after field "Accumulations"
put tData into URL "ftp://ftp.myftpserver.com"
put homegrownMP3Data into URL "binfile:My file.MP3"
Related
property: explicitVariables
command: delete URL, put, local, open file, libURLftpUpload, libURLDownloadToFile
control structure: function
function: result, value, URLEncode
glossary: handler, variable, property, blocking, binary file, command, declare, resource fork, error, expression, local variable, upload, server, statement, container
keyword: binfile, ftp, message box, file, resfile, binfile, URL, resfile, http, after, field, before, http, word
message: urlProgress
Compatibility and Support
Introduced
LiveCode 1.0
OS
mac
windows
linux
ios
android
web
Platforms
desktop
server
mobile